import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:get/get.dart';
import 'package:yi_shop/utils/colors.dart';
import 'package:yi_shop/utils/styles.dart';
import 'package:yi_shop/utils/svg.dart';
import 'package:yi_shop/utils/tools.dart';

class InvoiceModifyController extends GetxController {
  RxBool isPersonage = RxBool(true);

  RxBool isDefault = true.obs;
}

class InvoiceModifyPage extends GetView<InvoiceModifyController> {
  const InvoiceModifyPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ToolsUtils.builderLeading(),
        title: Text(
          '发票抬头',
          style: StylesUtils.customTextStyle(
              fontWeight: FontWeight.w700, fontSize: StylesUtils.fontSize18),
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              height: 40,
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              alignment: Alignment.centerLeft,
              child: Wrap(
                crossAxisAlignment: WrapCrossAlignment.center,
                alignment: WrapAlignment.start,
                spacing: 20,
                children: [
                  Obx(() => InkWell(
                      onTap: () {
                        controller.isPersonage.value = true;
                      },
                      child: Text.rich(TextSpan(children: [
                        WidgetSpan(
                            child: SvgUtils.assetName(
                                controller.isPersonage.isTrue ? 'u12520' : 'u13059',
                                width: 20,
                                height: 20),
                            alignment: PlaceholderAlignment.middle),
                        TextSpan(
                            text: ' 个人',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color3333))
                      ])))),
                  Obx(() => InkWell(
                      onTap: () {
                        controller.isPersonage.value = false;
                      },
                      child: Text.rich(TextSpan(children: [
                        WidgetSpan(
                            child: SvgUtils.assetName(
                                controller.isPersonage.isFalse ? 'u12520' : 'u13059',
                                width: 20,
                                height: 20),
                            alignment: PlaceholderAlignment.middle),
                        TextSpan(
                            text: ' 公司',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color3333))
                      ]))))
                ],
              ),
            ),
            Container(
              height: 50,
              padding: EdgeInsets.only(left: 15.w, right: 10.w),
              decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border(
                      bottom: BorderSide(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '发票抬头',
                    style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                  ),
                  Expanded(
                      child: Container(
                    alignment: Alignment.centerRight,
                    child: TextField(
                      cursorHeight: 15,
                      cursorWidth: 3,
                      cursorColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                      cursorRadius: const Radius.circular(2),
                      cursorOpacityAnimates: false,
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                      textAlign: TextAlign.right,
                      decoration: InputDecoration(
                          hintText: '请输入准确的抬头名称',
                          hintStyle: StylesUtils.customTextStyle(
                              color: ColorsUtils.color9999, fontSize: StylesUtils.fontSize13),
                          border: InputBorder.none,
                          focusedBorder: InputBorder.none,
                          isCollapsed: false,
                          isDense: false,
                          contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                          constraints: const BoxConstraints.expand(height: 30)),
                      onChanged: (String value) {},
                    ),
                  ))
                ],
              ),
            ),
            Obx(() {
              if (controller.isPersonage.isFalse) {
                return Container(
                  height: 50,
                  padding: EdgeInsets.only(left: 15.w, right: 10.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border(
                          bottom: BorderSide(
                              color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '税号',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                      ),
                      Expanded(
                          child: Container(
                        alignment: Alignment.centerRight,
                        child: TextField(
                          cursorHeight: 15,
                          cursorWidth: 3,
                          cursorColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                          cursorRadius: const Radius.circular(2),
                          cursorOpacityAnimates: false,
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                          textAlign: TextAlign.right,
                          decoration: InputDecoration(
                              hintText: '请输入纳税人识别号',
                              hintStyle: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color9999, fontSize: StylesUtils.fontSize13),
                              border: InputBorder.none,
                              focusedBorder: InputBorder.none,
                              isCollapsed: false,
                              isDense: false,
                              contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                              constraints: const BoxConstraints.expand(height: 30)),
                          onChanged: (String value) {},
                        ),
                      ))
                    ],
                  ),
                );
              }
              return Container();
            }),
            Container(
              height: 50,
              padding: EdgeInsets.only(left: 15.w, right: 10.w),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '设为默认抬头',
                    style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                  ),
                  Obx(() => FlutterSwitch(
                    width: 48,
                    height: 24,
                    activeToggleColor: Colors.white,
                    activeColor:
                    ColorsUtils.parseColorFromHexString(ColorsUtils.colorF26f),
                    inactiveColor:
                    ColorsUtils.parseColorFromHexString(ColorsUtils.colorCccc),
                    toggleSize: 22,
                    padding: 2,
                    value: controller.isDefault.value,
                    onToggle: (bool value) {
                      controller.isDefault.value = value;
                    },
                  ))
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 20),
              height: 50,
              padding: EdgeInsets.only(left: 15.w, right: 10.w),
              decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border(
                      bottom: BorderSide(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '手机号码',
                    style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                  ),
                  Expanded(
                      child: Container(
                    alignment: Alignment.centerRight,
                    child: TextField(
                      cursorHeight: 15,
                      cursorWidth: 3,
                      cursorColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                      cursorRadius: const Radius.circular(2),
                      cursorOpacityAnimates: false,
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                      textAlign: TextAlign.right,
                      keyboardType: TextInputType.phone,
                      decoration: InputDecoration(
                          hintText: '选填',
                          hintStyle: StylesUtils.customTextStyle(
                              color: ColorsUtils.color9999, fontSize: StylesUtils.fontSize13),
                          border: InputBorder.none,
                          focusedBorder: InputBorder.none,
                          isCollapsed: false,
                          isDense: false,
                          contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                          constraints: const BoxConstraints.expand(height: 30)),
                      onChanged: (String value) {},
                    ),
                  ))
                ],
              ),
            ),
            Container(
              height: 50,
              padding: EdgeInsets.only(left: 15.w, right: 10.w),
              decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border(
                      bottom: BorderSide(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '电子邮箱',
                    style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                  ),
                  Expanded(
                      child: Container(
                    alignment: Alignment.centerRight,
                    child: TextField(
                      cursorHeight: 15,
                      cursorWidth: 3,
                      cursorColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                      cursorRadius: const Radius.circular(2),
                      cursorOpacityAnimates: false,
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                      textAlign: TextAlign.right,
                      keyboardType: TextInputType.emailAddress,
                      decoration: InputDecoration(
                          hintText: '选填',
                          hintStyle: StylesUtils.customTextStyle(
                              color: ColorsUtils.color9999, fontSize: StylesUtils.fontSize13),
                          border: InputBorder.none,
                          focusedBorder: InputBorder.none,
                          isCollapsed: false,
                          isDense: false,
                          contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                          constraints: const BoxConstraints.expand(height: 30)),
                      onChanged: (String value) {},
                    ),
                  ))
                ],
              ),
            ),
            Obx(() {
              if (controller.isPersonage.isFalse) {
                return ListBody(
                  children: [
                    Container(
                      height: 50,
                      padding: EdgeInsets.only(left: 15.w, right: 10.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          border: Border(
                              bottom: BorderSide(
                                  color:
                                      ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '单位地址',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                          ),
                          Expanded(
                              child: Container(
                            alignment: Alignment.centerRight,
                            child: TextField(
                              cursorHeight: 15,
                              cursorWidth: 3,
                              cursorColor:
                                  ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                              cursorRadius: const Radius.circular(2),
                              cursorOpacityAnimates: false,
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                              textAlign: TextAlign.right,
                              keyboardType: TextInputType.text,
                              decoration: InputDecoration(
                                  hintText: '选填',
                                  hintStyle: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color9999,
                                      fontSize: StylesUtils.fontSize13),
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  isCollapsed: false,
                                  isDense: false,
                                  contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                                  constraints: const BoxConstraints.expand(height: 30)),
                              onChanged: (String value) {},
                            ),
                          ))
                        ],
                      ),
                    ),
                    Container(
                      height: 50,
                      padding: EdgeInsets.only(left: 15.w, right: 10.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          border: Border(
                              bottom: BorderSide(
                                  color:
                                      ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '开户银行',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                          ),
                          Expanded(
                              child: Container(
                            alignment: Alignment.centerRight,
                            child: TextField(
                              cursorHeight: 15,
                              cursorWidth: 3,
                              cursorColor:
                                  ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                              cursorRadius: const Radius.circular(2),
                              cursorOpacityAnimates: false,
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                              textAlign: TextAlign.right,
                              keyboardType: TextInputType.text,
                              decoration: InputDecoration(
                                  hintText: '选填',
                                  hintStyle: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color9999,
                                      fontSize: StylesUtils.fontSize13),
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  isCollapsed: false,
                                  isDense: false,
                                  contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                                  constraints: const BoxConstraints.expand(height: 30)),
                              onChanged: (String value) {},
                            ),
                          ))
                        ],
                      ),
                    ),
                    Container(
                      height: 50,
                      padding: EdgeInsets.only(left: 15.w, right: 10.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          border: Border(
                              bottom: BorderSide(
                                  color:
                                      ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '银行账号',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                          ),
                          Expanded(
                              child: Container(
                            alignment: Alignment.centerRight,
                            child: TextField(
                              cursorHeight: 15,
                              cursorWidth: 3,
                              cursorColor:
                                  ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
                              cursorRadius: const Radius.circular(2),
                              cursorOpacityAnimates: false,
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                              textAlign: TextAlign.right,
                              keyboardType: TextInputType.number,
                              decoration: InputDecoration(
                                  hintText: '选填',
                                  hintStyle: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color9999,
                                      fontSize: StylesUtils.fontSize13),
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  isCollapsed: false,
                                  isDense: false,
                                  contentPadding: const EdgeInsets.only(left: 15, bottom: 10),
                                  constraints: const BoxConstraints.expand(height: 30)),
                              onChanged: (String value) {},
                            ),
                          ))
                        ],
                      ),
                    ),
                  ],
                );
              }
              return Container();
            }),
            Container(
              margin: const EdgeInsets.only(top: 30),
              alignment: Alignment.center,
              child: TextButton(
                  onPressed: () {},
                  style: ButtonStyle(
                      minimumSize: MaterialStatePropertyAll(Size(335.w, 50)),
                      backgroundColor: MaterialStatePropertyAll(ColorsUtils.rgba(128, 128, 255, 1)),
                      shape: MaterialStatePropertyAll(
                          RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.r)))),
                  child: Text('保存', style: StylesUtils.customTextStyle(),)),
            )
          ],
        ),
      ),
    );
  }
}
